<template>
  <div class="category-management">
    <el-card shadow="never">
      <el-form ref="searchForm" :model="form" label-width="80px" label-position="right">
        <el-row :gutter="32">
          <el-col :md="8">
            <el-form-item label="地区名称">
              <el-input
                v-model="form.name"
                clearable
                placeholder="请输入地区名称"
              />
            </el-form-item>
          </el-col>
          <el-col :md="16">
            <el-form-item align="right">
              <el-button type="primary" @click="$showNoAuthMsg()">查 询</el-button>
              <el-button plain @click="$showNoAuthMsg()">重 置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        ref="treeTable"
        v-loading="loading"
        :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        row-key="id"
        :expand-row-keys="expandID"
        stripe
        :tree-props="{children: 'children'}"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        class="table-data"
      >
        <el-table-column prop="name" label="地区名称" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="cityCode" label="城市编码" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="isDelete" label="是否启用" align="center" :show-overflow-tooltip="true" min-width="150">
          <template slot-scope="scope">
            <span> {{ scope.row.isDelete == 0 ? '启用' : '禁用' }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import { getCityTree } from '@/api/basic'
export default {
  data() {
    return {
      form: {
        name: ''
      },
      expandID: [],
      tableData: [],
      loading: false,
      currentPage: 1,
      pagesize: 10,
      total: 0
    }
  },
  mounted() {
    this.getCityTree()
  },
  methods: {
    async getCityTree() {
      try {
        this.loading = true
        const res = await getCityTree()
        this.loading = false
        this.tableData = res
        this.total = this.tableData.length
      } catch (error) {
        this.loading = false
        console.log(error)
      }
    },
    handleSizeChange(val) {
      this.pagesize = val
    },
    handleCurrentChange(val) {
      this.currentPage = val
    }
  }
}
</script>
<style lang="scss" scoped>
  .table-data{
    margin: 30px 0px;
  }
  .el-pagination {
    text-align: right;
    margin-right: 20px;
  }

</style>
